
import math from "@/_js/math";
const weexFunction = weex.requireModule("WeexFunction");

export default {
  
  /** 获取指定参数
   * 
   * @param {Array} reserves //参数数组
   * @param {String} name 
   */
  getParam(reserves, name) {

    var datas = JSON.parse(JSON.stringify(reserves));
    for (let index = 0; index < datas.length; index++) {
      var data = datas[index];

      if (data.ref) {
        for (let index = 0; index < data.values.length; index++) { 
          var value = data.values[index];
          if (value.name == name) {
            return value;
          }
        }
      } else if (data.name == name) {
        return data;
      }
    }
    return null;
  },

  /** 获取网格最大交易对数量
   * 
   * @param {String} balance //投资币持仓数量
   * @param {String} onInvest  //单格投入
   * @param {String} investCoin  //投资币
   * @param {String} pairMap  //交易对
   * 
   */
  getGridManyPair(balance, onInvest, investCoin, pairMap){
    
    var baseCoinUsdPrice =  math.chu(pairMap.usdPrice, pairMap.last);
    var counterCoinUsdPrice =  pairMap.usdPrice;
    var bol = investCoin == pairMap.baseCoin;
    var price = bol ? baseCoinUsdPrice : counterCoinUsdPrice;
    var xiaoshu = bol ? pairMap.baseCoinDecimal : pairMap.counterCoinDecimal;
    xiaoshu = math.getNumber(xiaoshu);
    
    var onNorm = investCoin == 'USDT' ? '100' : math.chu('100', price);
    if (onInvest) {
      onNorm = math.getNumber(onInvest) > math.getNumber(onNorm) ? onInvest : onNorm;
    }
    var maxPairNumber =  math.chu(balance, onNorm, 0, 2);
    maxPairNumber = math.getNumber(maxPairNumber) > 50 ? '50' : maxPairNumber;
    //最大币对数量 = 剩余可用资金/max[单格投入，单币对策略投入资金下限(即100u)]
    return math.getNumber(maxPairNumber);
  },
}